/*
 * CPlayList.h
 *
 *  Created on: 20.2.2009
 *      Author: JariTimoMiia
 */

#ifndef CPLAYLIST_H_
#define CPLAYLIST_H_
#include "CMusic.h"
#include <vector>
#include <string>

typedef CMusic* pMusic;

using namespace std;
//class CMusic;

class CPlayList {
private:
	vector<pMusic> m_playlist;

public:
	bool Init() {
		SDL_Init(SDL_INIT_AUDIO);

		if (Mix_OpenAudio(FREQUENCY, MIX_DEFAULT_FORMAT, CHANNELS, CHUNKSIZE)) {
#ifdef DEBUG
            CLogger::Instance()->log(LOG_LEVEL_ERROR,"CPlayList::Init : Unable to init audio!\n");
#endif
			return false;
		}
		return true;
	}

	void Cleanup() {
		while (!m_playlist.empty()) {
			m_playlist.back()->Close();
			m_playlist.pop_back();
		}
		Mix_CloseAudio();
	}

	void AddMusic(pMusic song, string filename) {
		m_playlist.push_back(song);
		m_playlist.back()->LoadMusic(filename);
	}

	void CreateList() {
		//TODO: create lists automaticly from directory listing?
		AddMusic(new CMusic(), "testmusic1.mp3");
		AddMusic(new CMusic(), "testmusic2.mp3");

	}

	void PlayMusic() {
		m_playlist.back()->Play();
	}

};

#endif /* CPLAYLIST_H_ */
